/**
 * An object of type <code>Card</code> represents a playing card from a
 * standard english deck of cards.  The card has a suit, which
 * can be spades, hearts, diamonds, or clubs.  A spade, heart,
 * diamond, or club has one of the 13 values: ace, 2, 3, 4, 5, 6, 7,
 * 8, 9, 10, jack, queen, or king.  Note that "ace" is considered to be
 * the smallest value.
 *
 *@author DIATEL curso 2012-2013
 *@version 1.0
 *
 */
package blackjack;
public class Card {
   
   public final static int SPADES = 0;       // Codes for the 4 suits.
   public final static int HEARTS = 1;
   public final static int DIAMONDS = 2;
   public final static int CLUBS = 3;
   
   public final static int ACE = 1;          // Codes for the non-numeric cards.
   public final static int JACK = 11;        // Cards 2 through 10 have their 
   public final static int QUEEN = 12;       // numerical values for their codes.
   public final static int KING = 13;

   /**
    * The different suits of the english deck: SPADES, HEARTS, DIAMONDS, CLUBS.
    */
   public final static int [] Suits = { SPADES, HEARTS, DIAMONDS, CLUBS };

   /**
    * The different values of the english deck cards: ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, JACK, QUEEN, KING.
    */
   public final static int [] Values = { ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, JACK, QUEEN, KING };
   
   /**
    * This card's suit.  The suit cannot be changed after the card is
    * constructed.
    */
   private final int suit; 
   
   /**
    * The card's value.  The value cannot be changed after the card
    * is constructed.
    */
   private final int value;
   
   /**
    * Creates a <code>Card</code> with a specified suit and value.
    * @param theValue Value of the new card. It must be in the range 1
    * through 13, with 1 representing an Ace.
    * You can use the constants Card.ACE, Card.JACK, Card.QUEEN, and Card.KING.  
    * 
    * @param theSuit the suit of the new card.  This must be one of the values
    * Card.SPADES, Card.HEARTS, Card.DIAMONDS, Card.CLUBS, or Card.JOKER.
    *
    * @throws IllegalArgumentException if the parameter values are not in the
    * Permissible ranges
    */
   public Card(int theValue, int theSuit) {
      if (theSuit != SPADES && theSuit != HEARTS && theSuit != DIAMONDS && 
            theSuit != CLUBS)
         throw new IllegalArgumentException("Illegal playing card suit");
      if (theValue < 1 || theValue > 13)
         throw new IllegalArgumentException("Illegal playing card value");
      value = theValue;
      suit = theSuit;
   }

   /**
    * Returns the suit of this card.
    *
    * @return Card suit, which is one of the constants Card.SPADES, 
    * Card.HEARTS, Card.DIAMONDS, or Card.CLUBS
    *
    */
   public int getSuit() {
      return suit;
   }
   
   /**
    * Returns the value of this card.
    *
    * @return the value, which is one of the numbers 1 through 13, inclusive.
    */
   public int getValue() {
      return value;
   }
   
   /**
    * Returns a String representation of the card's suit.
    *
    * @return one of the strings "Spades", "Hearts", "Diamonds", or "Clubs".
    */
   public String getSuitAsString() {
      switch ( suit ) {
      case SPADES:   return "Spades";
      case HEARTS:   return "Hearts";
      case DIAMONDS: return "Diamonds";
      case CLUBS:
      default:      return "Clubs";
      }
   }
   
   /**
    * Returns a String representation of the card's value.
    *
    * @return  one of the strings "Ace", "2",
    * "3", ..., "10", "Jack", "Queen", or "King".
    */
   public String getValueAsString() {
      switch ( value ) {
         case 1:   return "Ace";
         case 2:   return "2";
         case 3:   return "3";
         case 4:   return "4";
         case 5:   return "5";
         case 6:   return "6";
         case 7:   return "7";
         case 8:   return "8";
         case 9:   return "9";
         case 10:  return "10";
         case 11:  return "Jack";
         case 12:  return "Queen";
         case 13:
         default:  return "King";
      }
   }
   
   /**
    * Returns a string representation of this card, including both
    * its suit and its value.  Sample return values
    * are: "Queen of Hearts", "10 of Diamonds", "Ace of Spades".
    *
    * @return  a string representation of this card
    */
   @Override
   public String toString() {
      return getValueAsString() + " of " + getSuitAsString();
   }

}